package com.gohi.main.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.jianzhou.sdk.BusinessService;

/**
 * 发送短信的接口
 * 
 * @author 肖得明
 * 
 */
public class MsgUtils {
	// 注册验证码
	private static final String MSG_REGCODE = "验证码：%s，仅用于注册，请勿告知他人【约来约美】";
	// 注册验证码
	private static final String FIND_PWDCODE = "验证码：%s，仅用于密码找回，请勿告知他人【约来约美】";
	// 预约
	private static final String MSG_YUYUE = "您已成功预约%s，消费码：%s【约来约美】";

	// 您已成功预约$store$beautician XXXX年XX月XX号 XX:XX:00-XX:XX:00
	// 的服务，到店请出示消费码：$code，请勿爽约，店家联系方式：XXXXXXXXXXXX【约美丽】

	/**
	 * 发送短信
	 * 
	 * @param type 1为注册
	 * @param code
	 * @return
	 */
	public static boolean SendMsg(String mobile, String code) {
		BusinessService bs = new BusinessService();
		bs.setWebService("http://www.jianzhou.sh.cn/JianzhouSMSWSServer/services/BusinessService");
		bs.sendBatchMessage("sdk_goomeirong", "881230", mobile, code);
		return true;
	}

	// 格式化短信验证码
	public static String getRegCode(String code) {
		return String.format(MSG_REGCODE, code);
	}

		// 格式化密码找回短信验证码
		public static String getFindPwdCode(String code) {
			return String.format(FIND_PWDCODE, code);
		}
	
	public static String getYuyue(String storename, String code) {
		return String.format(MSG_YUYUE, storename, code);
	}

	public static boolean isMobile(String str) {
		Pattern p = null;
		Matcher m = null;
		boolean b = false;
		p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号
		m = p.matcher(str);
		b = m.matches();
		return b;
	}

	public static String getpwd() {
		return Math.round(Math.random() * 9000 + 1000) + ""
				+ Math.round(Math.random() * 9000 + 1000) + ""
				+ Math.round(Math.random() * 9000 + 1000);
	}
}
